#!/bin/sh

export ROOTDIR=${ROOTDIR:="$(pwd)/../../.."}

export APP=$1
export SITE=$2
HOSTS=$3

conf=$(cat $ROOTDIR/opt/site/kohana/default.conf | sed s/APP/$APP/g)
mkdir -p $ROOTDIR/var/log/$APP
echo "$conf" >| $ROOTDIR/etc/sites/sites.d/${APP}.conf
ln -s "$SITE" "$ROOTDIR/var/sites/$APP"

if [ $HOSTS == "-h" ] ; then
	$ROOTDIR/crosslight.sh site hosts $APP
fi

VERSION="3.2.2"
URL="http://cloud.github.com/downloads/kohana/kohana/kohana-${VERSION}.zip"
cd $ROOTDIR/var/sites/$APP

curl $URL > kohana.zip
unzip kohana.zip >/dev/null
mv kohana/* .
rm -rf kohana* install.php
cd -
